﻿using UnityEngine;
using System.Collections;

public class WeaponController : MonoBehaviour {

	public GameObject PrimaryWeaponPrefab;
	
	private GameObject primaryWeapon;
	private WeaponInterface primaryWeaponInterface;

	// Use this for initialization
	void Start () {
		InstallPrimaryWeapon();
	}
	
	// Update is called once per frame
	void Update () {
		if (Input.GetKey (KeyCode.J) && primaryWeaponInterface) {
			primaryWeaponInterface.Fire(gameObject.transform.forward);
		}
	}

	public void InstallPrimaryWeapon () {
		if (primaryWeapon) {
			Destroy(primaryWeapon);
		}
		if (PrimaryWeaponPrefab) {
			primaryWeapon = Instantiate<GameObject>(PrimaryWeaponPrefab);
			primaryWeapon.transform.SetParent(gameObject.transform);
			primaryWeapon.transform.localPosition = Vector3.zero;
			primaryWeaponInterface = primaryWeapon.GetComponent<WeaponInterface>();
			primaryWeaponInterface.TargetTag = "Emermy";
		}
	}
}
